package com.woniuxy.goods.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.core.annotation.Permission;
import com.woniuxy.core.util.Result;
import com.woniuxy.goods.entity.Brand;
import com.woniuxy.goods.entity.GoodsBrandCat;
import com.woniuxy.goods.form.AddBrandCatForm;
import com.woniuxy.goods.form.AddGoodsCatForm;
import com.woniuxy.goods.form.UpdateBrandCatForm;
import com.woniuxy.goods.param.AddBrandCatParam;
import com.woniuxy.goods.param.AddGoodsCatParam;
import com.woniuxy.goods.param.UpdateBrandCatParam;
import com.woniuxy.goods.service.GoodsBrandCatService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * <p>
 *  前端控制器
 * </p>
 * 品牌、类别绑定控制层接口
 * @author ...
 * @since 2024年05月22日
 */
@RestController
@Api(tags = "品牌、类别绑定管理接口")
@RequestMapping("/goodsBrandCat")
public class GoodsBrandCatController {
    /**
     * 品牌、类别绑定服务层接口
     */
    @Resource
    private GoodsBrandCatService goodsBrandCatService;

    /**
     * 绑定典当物品品牌类别
     * @param form 新增品牌类别绑定对象
     * @return 品牌类别信息集合
     * @throws Exception
     */
    @ApiOperation("绑定典当物品品牌类别")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = GoodsBrandCat.class)
    })
    @PostMapping("/addBrandCatConfig")
    @Permission(roles = {"超级管理员","管理员"})
    public Result addBrandCatConfig(@RequestBody AddBrandCatForm form)throws Exception{
        List<GoodsBrandCat> brandCats = goodsBrandCatService.addBrandCatConfig(BeanUtil.toBean(form, AddBrandCatParam.class));
        return Result.success("绑定典当物品品牌类别成功",brandCats);
    }

    /**
     * 解绑典当物品品牌类别
     * @param ids 品牌、类别绑定信息id
     * @return
     * @throws Exception
     */
    @ApiOperation("解绑典当物品品牌类别")
    @ApiImplicitParam("品牌、类别绑定信息id")
    @PostMapping("/delBrandCatConfig")
    @Permission(roles = {"超级管理员","管理员"})
    public Result delBrandCatConfig(@RequestBody Set<Integer> ids)throws Exception{
        goodsBrandCatService.delBrandCatConfig(ids);
        return Result.success("解绑典当物品品牌类别成功",null);
    }

    /**
     * 换绑典当物品品牌类别
     * @param form 修改品牌类别绑定对象
     * @return 品牌类别信息
     * @throws Exception
     */
    @ApiOperation("换绑典当物品品牌类别")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = GoodsBrandCat.class)
    })
    @PostMapping("/updateBrandCatConfig")
    @Permission(roles = {"超级管理员","管理员"})
    public Result updateBrandCatConfig(@RequestBody UpdateBrandCatForm form)throws Exception{
        GoodsBrandCat brandCat = goodsBrandCatService.updateBrandCatConfig(BeanUtil.toBean(form, UpdateBrandCatParam.class));
        return Result.success("换绑典当物品品牌类别成功",brandCat);
    }

    /**
     * 通过品牌id换绑典当物品品牌类别
     * @param form 新增品牌类别绑定对象
     * @return 品牌类别信息集合
     * @throws Exception
     */
    @ApiOperation("通过品牌id换绑典当物品品牌类别")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = GoodsBrandCat.class)
    })
    @PostMapping("/updateBrandCatByBrandId")
    @Permission(roles = {"超级管理员","管理员"})
    public Result updateBrandCatByBrandId(@RequestBody AddBrandCatForm form)throws Exception{
        List<GoodsBrandCat> brandCats = goodsBrandCatService.updateBrandCatByBrandId(BeanUtil.toBean(form, AddBrandCatParam.class));
        return Result.success("通过品牌id换绑典当物品品牌类别成功",brandCats);
    }

    /**
     * 通过典当物品品牌id查绑定的类别ids
     * @param brandId 品牌id
     * @return 绑定记录集合
     * @throws Exception
     */
    @ApiOperation("通过典当物品品牌id查绑定记录集合")
    @ApiImplicitParam("品牌id")
    @GetMapping("/findCatIdsByBrandId")
    public Result findCatIdsByBrandId(Integer brandId)throws Exception{
        Set<Integer> catIds= goodsBrandCatService.findCatIdsByBrandId(brandId);
        return Result.success("通过典当物品品牌id查绑定的类别ids成功",catIds);
    }

    /**
     * 通过典当物品类别id查绑定的品牌ids
     * @param catId 类别id
     * @return 品牌id集合
     * @throws Exception
     */
    @ApiOperation("通过典当物品类别id查绑定的品牌ids")
    @ApiImplicitParam("类别id")
    @GetMapping("/findBrandIdsByCatId")
    public Result findBrandIdsByCatId(Integer catId)throws Exception{
        Set<Integer> brandIds= goodsBrandCatService.findBrandIdsByCatId(catId);
        return Result.success("通过典当物品类别id查绑定的品牌ids成功",brandIds);
    }

}

